<?php
namespace Home\Model;
use Think\Model;
class RegModel extends Model {

    protected $tableName = "information";

    protected $_validate = array(
        array('name','require','登录名必须填写'),
        array('password','require','密码必须填写'),
        array('phone','require','手机必须填写正确',['^1[3,4,5,7,8]\d{9}$'])
    );

    function Reg()
    {
        $input = $this->create();
        if (empty($input)) {
            return;
        }


        $openid = session('openid');
        $where['openid'] = $openid;

        $password = $_REQUEST['password'];
        $phone = $_REQUEST['phone'];
        $name = $_REQUEST['name'];//账号

        $password = md5($password).'cj';//md5加密过后的密码

        $data['name'] =$name;
        $data['password'] =$password;
        $data['phone'] = $phone;

        $add = $this->where($where)->save($data);

//        $id = session('openid');
        $where['openid'] = $openid;
        $na = M('information')->where($where)->select();
        $idpu = $na[0]['idi'];
        if(!empty($na)){

        }

        if(empty($add)){
            $this->error="账号也存在";
        }
        return $na;
    }

}